﻿using TicketReservationSystem.Common.Entities;
using TicketReservationSystem.Common.Interfaces;
using TicketReservationSystem.Common.Utils;

namespace TicketReservationSystem.TicketReservation
{
    public class TicketReservation : ITicketReservation
    {
        private readonly IDataAccess data;

        public TicketReservation(IDataAccess data)
        {
            this.data = data;
        }

        public Result ReserveTicket(Reservation reservation)
        {
            if (!data.Exists(reservation.Customer))
            {
                data.Add(reservation.Customer);
            }

            if (data.Exists(reservation)) return Result.AlreadyExists;

            data.Add(reservation);

            return Result.Ok;
        }
    }
}
